using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PacmanMove : MonoBehaviour
{
    public float moveSpeed;

    private Rigidbody2D rb;
    private SelfAnim animator;


    void Start()
    {
       
        rb = GetComponent<Rigidbody2D>();
        animator = GetComponent<SelfAnim>();
    }

   
    void Update()
    {
        if (GameMgr.Instance.isStartGame)
        {
            Vector2 move = Vector2.zero;

   
            if (Input.GetKey(KeyCode.D))
            {
                move = Vector2.right * moveSpeed; 
                animator.ChangeDir(SelfAnim.Anim_Dir.Right); 
            }
            else if (Input.GetKey(KeyCode.A))
            {
                move = Vector2.left * moveSpeed;
                animator.ChangeDir(SelfAnim.Anim_Dir.Left);
            }
            else if (Input.GetKey(KeyCode.W))
            {
                move = Vector2.up * moveSpeed;
                animator.ChangeDir(SelfAnim.Anim_Dir.Up);
            }
            else if (Input.GetKey(KeyCode.S))
            {
                move = Vector2.down * moveSpeed;
                animator.ChangeDir(SelfAnim.Anim_Dir.Down);
            }

    
            if (move != Vector2.zero)
            {
                rb.MovePosition(rb.position + move * Time.deltaTime);
            }
        }
    }

 
}